#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=200010;
const long long INF=1000000000000000010;
int n;
ll a[N],pre[N];
ll dp[N][2],f[N][2];
int pos[N],lst[1000010];
void slv(){
    for(int i=1;i<=1000000;i++) lst[i]=-1;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    pre[0]=0;
    pos[0]=-1;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]) pre[i]=a[i];
        else pre[i]=0;
        pre[i]+=pre[i-1];
        pos[i]=lst[a[i]];
        lst[a[i-1]]=i-1;
//        cout<<pos[i]<<" ";
    }
//    cout<<endl;
    for(int i=0;i<n;i++) for(int j=0;j<2;j++) dp[i][j]=f[i][j]=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<2;j++){
            if(a[i]==a[i-1]) dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i]);
            else dp[i][j]=max(dp[i][j],dp[i-1][j]);
            dp[i][j]=max(dp[i][j],dp[i-1][j^1]);
            f[i-1][j^1]=max(f[i-1][j^1],dp[i-1][j^1]);
            if(pos[i]!=-1){
                dp[i][j]=max(dp[i][j],f[pos[i]][j]+pre[i-1]-pre[pos[i]+1]+a[i]);
                f[i-1][j^1]=max(f[i-1][j^1],f[pos[i]][j]+pre[i-1]-pre[pos[i]+1]+a[i]);
            }
        }
//        cout<<i<<":"<<dp[i][0]<<" "<<dp[i][1]<<endl;
    }
    cout<<max(dp[n-1][0],dp[n-1][1])<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--) slv();
    return 0;
}